package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Patient;
import com.example.demo.mapper.PatientMapper;
import com.example.demo.service.PatientService;
import org.springframework.stereotype.Service;

@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    // 假设患者登录是用 phone + password 查询（需要 patients 表有 password 字段，否则登录逻辑要在 user 表处理）
    @Override
    public Patient login(String phone, String password) {
        QueryWrapper<Patient> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone).eq("password", password); // 如果没有password字段，这句要改
        return this.getOne(queryWrapper);
    }

    @Override
    public Patient getByUserId(Integer userId) {
        QueryWrapper<Patient> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);  // 这里要确保patients表有 user_id字段，否则改为合适字段
        return this.getOne(queryWrapper);
    }
}
